	*==============================
	* Create temporary threat data
	*==============================
	
	use "$temp_dir\threat_2010.dta", clear
	append using "$temp_dir\threat_2011.dta"
	append using "$temp_dir\threat_2012.dta"
	save "$temp_dir\threat_all_years.dta", replace
	
	
	
	
	*==========================================
	* merge observation panel with threat data
	*==========================================
	use "$basefiles\\$basefile_observation", clear
	merge 1:1 id year using "$basefiles\\$basefile_teacher"
	*destring id, replace
	keep if year == 2010 | year == 2011 | year == 2012
	keep if _merge == 3
	drop _merge
	merge 1:1 id year using "$temp_dir\threat_all_years.dta"
	keep if _merge == 3
	drop _merge
	
	* save noiva data
	save "$input_dir\teacher_threat_noiva.dta", replace
	
	/*
	*======================*
	* Create IVA database:
	*======================*
	
	* fixe raw IVA stuff
	
	use "$dir\build\input\basefiles\IVAraw.dta", clear
	rename ivaread_raw_0910 ivaread_raw_2010
	rename ivaread_raw_1011 ivaread_raw_2011
	rename ivaread_raw_1112 ivaread_raw_2012
	rename ivamath_raw_0910 ivamath_raw_2010
	rename ivamath_raw_1011 ivamath_raw_2011
	rename ivamath_raw_1112 ivamath_raw_2012
	reshape long ivaread_raw_ ivamath_raw_, i(id) j(year)
	rename ivaread_raw_ ivaread_raw
	rename ivamath_raw_ ivamath_raw
	drop ivaread_exp_* ivamath_exp_* ivaread_act_* ivamath_act_* 
	destring id, replace
	
	save "$temp_dir\iva_raw_long.dta", replace
	
	* add IVA raw
	merge 1:1 id year using "$temp_dir\iva_raw_long.dta"
	keep if _merge == 3
	drop _merge
	save "$input_dir\teacher_threat_iva.dta", replace
	*/
	
	
	*merge 1:1 id year using "$input_dir\student_mean_scores.dta"
	*drop _merge
	
	*merge 1:1 id year using "$temp_dir\teacher_grade_year.dta"
	*drop _merge
	